<template>
  <div class="ability">
    <el-collapse v-model="activeName"  @change="handleChange">
      <el-collapse-item v-for="accessItems in ASSESS_ITEM" :name="accessItems.setId">
        <template slot="title">
          {{accessItems.setName}} <i v-if="accessItems.complete == 0" style="color: gray;">未完成</i>
          <i v-else-if="accessItems.complete == 1" style="color: green;">已完成</i>
        </template>
        <div class="assessmentContent" v-for="accessItem in accessItems.assessItemDTOList">
          <div class="assessmentTitle" >
            <label>{{accessItem.itemNo}}.{{accessItem.itemTitle}}</label>
          </div>
          <div class="assessmentItem">
            <options :options="accessItem.assessItemResultDTOList"
                     :type="accessItem.type"
                     :other="accessItem.other"
                     :itemId="accessItem.itemId"
                     :setId = "accessItem.setId"
                     :optionsDisabled = "optionsDisabled"
                     @updateOption = "updateOption"
            ></options>
          </div>
        </div>
        <div class="assessmentMark">
          <reference :reference="accessItems.assessSetResultDTOList"></reference>
        </div>
        <div class="assessmentInput">
          <inputs :results = "results"
                  :setresult = "accessItems.assessmentResultDTO"
                  :setId= "accessItems.setId"
                  :currentTasId = "affirmCurrentTasId"
                  :careJudgment = "accessItems.assessSetResultDTOList"
                  :member = "member"
                  :optionsLength="accessItems.assessItemDTOList.length"
          ></inputs>
        </div>
      </el-collapse-item>
    </el-collapse>
    <div class="examine-result">
      <el-button class="lightGreenBtn" type="info" :disabled="disabled" @click="getResult">查看评估结果</el-button>
      <!--<el-button type="info" :disabled="disabled" @click="isPlan">制定服务计划</el-button>-->
    </div>
    <div class="evaluation-result" v-show="isResultShow">
      <resultSheet :resultEvaluation = "resultEvaluation" :member="member"  :resultHealthy="results"  :currentTasId="currentTasId" @goto="goto"></resultSheet>
    </div>

  </div>
</template>

<script>
  import options from './abilityContent/options';
  import inputs from './abilityContent/inputs';
  import reference from "./abilityContent/reference";
  import resultSheet from "./abilityContent/resultSheet";
  import planMake from "./planMake";
  import checkInApi from '../../service/member/checkInApi';
  import commonApi from '../../service/member/commonApi';

  export default {
    data(){
      return{
        optionsDisabled:false,
        isResultShow:false,
        isSubmit:false,
        disabled:false,
        activeName:"1",
        radio2: 3,
        currentView:"resultSheet",
        currentAccessId:0,
        assessId:0,
        sheetId:0,
        itemResult:[],
        ASSESS_ITEM:[],
        results:{
          "assessId": 0,
          "auditTime": "",
          "auditUser": "",
          "comment": "",
          "itemResultVOList": [],
          "rId": 0,
          "resultValue": 0,
          "setId": 0,
          "sheetId": 0,
          "resultName":""
        },
        resultEvaluation:{
          "assessmentResultDTO": {},
          "setResultInfoDTOList": [],
          "sheetResultDTOList": [],
          "serviceCareLevels": []

        },
        affirmCurrentTasId:0,
        careLevelOptions:null,
      }
    },
    props:["currentTasId","member"],
    methods: {
      init(){
        this.loadProject(1,this.member.memberId);
        this.affirmCurrentTasId = this.currentTasId;

      },
      /**
       *获取评估项目
       */
      loadProject(sheetType,memberId){
        let self = this;
        checkInApi.loadProject(sheetType,memberId).then(function(response){
          var data = response.body.data;
          if(data){
            self.ASSESS_ITEM = data.assessSetDTOList;
            var remain = 0;
            self.ASSESS_ITEM.forEach(function(accessItems){
              if(!accessItems.assessmentResultDTO){
                if(accessItems.complete == 0){
                  remain += 1;
                }
                accessItems.assessmentResultDTO = {
                  "assessId": 0,
                  "auditTime": "",
                  "auditUser": "",
                  "comment": "",
                  "rId": 0,
                  "resultValue": 0,
                  "setId": 0,
                  "sheetId": 0,
                  "resultName":""
                }
              }
            });
            self.results.assessId = data.assessId;
            self.results.sheetId = data.sheetId;
            if(remain == 0){
              self.getResult();
            }
          }
        });
      },
      goto(taskKey){
        this.$emit("goto",taskKey);
      },
      /**
       *获取评估信息
       */
      getProjectDetail(sheetType,memberId){
        let self = this;
        checkInApi.getProjectDetail(sheetType,memberId).then(function(response){
          self.ASSESS_ITEM = response.body.data;
        });
      },
      /**
       * 查看评估结果
       */
      getResult(){
        let self = this;
        self.currentView = "resultSheet";
         checkInApi.getAResult(self.results.assessId).then(function (response) {
           self.resultEvaluation = response.body.data;
           self.isResultShow = true;
         })
      },
      /**
       *
       *获得答案（子组件）
       */
      updateOption(val){
        if(val.itemId){
          for(var i=0;i<this.results.itemResultVOList.length;i++){
            if(this.results.itemResultVOList[i].itemId == val.itemId){
              this.results.itemResultVOList.splice(i,1);
            }
          }
          this.results.itemResultVOList.push(val);
        }
      },
      /**
       *制定服务计划
       */
      isPlan(){
        this.isResultShow = true;
        this.currentView = "planMake";
      }
    },
    components:{options,inputs, reference, resultSheet,planMake},
    mounted: function () {
      this.init();
    }
  }
</script>

<style>
  .ability .assessmentTitle{
    padding-bottom: 10px;
    font-size: 14px!important;
  }
  .ability .assessmentItem{
    padding-left: 15px;
    font-size: 14px!important;
  }
  .ability .assessmentItem label{
    display: block;
  }
  .ability .assessmentItem .el-radio+.el-radio,.el-checkbox+.el-checkbox{
    margin: 12px 0px!important;
  }
  .ability .assessmentItem textarea{
    width: 50%;
  }
  .ability .evaluation-result{
    background-color: #F2F8FE;
    padding:30px 60px;
  }
  .ability .examine-result{
    margin:20px;
  }

  .ability .reference{
    margin-bottom:7px;
  }
  .ability .assessmentInput{
    margin-top:20px;
  }
  .ability .assessmentInput label{
    margin-right:7px;
  }
  .ability .assessmentInput .el-row{
    margin-bottom:7px;
  }
  .ability .fen{
    color: #20a0ff;
    cursor: pointer;
  }
  .ability .fen:hover{
    color: #3fc6d2;
    cursor: pointer;
  }
</style>
